package com.bao.system.mapper;

import com.bao.system.entity.Effect;
import com.bao.vo.EffectVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bao
 * @since 2021-06-10
 */
@Repository
public interface EffectMapper extends BaseMapper<Effect> {

    @Select("<script>" +
            "select * " +
            "from tb_effect " +
            "where status = #{effectVO.status} " +
            "<if test='effectVO.inp!=\"\" and effectVO.inp!=\" \"'> " +
            "AND CONCAT(inp, outp) like CONCAT('%',#{effectVO.inp},'%') " +
            "</if> " +
            "<if test='effectVO.effectname!=\"\" and effectVO.effectname!=\" \"'> " +
            "AND effectname = #{effectVO.effectname} " +
            "</if>" +
            "<if test='effectVO.zone!=\"\" and effectVO.zone!=\" \"'>" +
            " AND zone = #{effectVO.zone} " +
            "</if>" +
            "</script>")
    IPage<Effect> findEffectPage(Page<Effect> page, EffectVO effectVO);

    @Delete("delete from tb_effect where tb_effect.id = #{id}")
    void deleEffet(Integer id);

    @Insert("insert into tb_effect (effectname, zone, description, application, func, condi, inp, outp, status, createtime) values " +
            "(#{effectname}, #{zone}, #{description}, #{application}, #{func}, #{condi}, #{inp}, #{outp}, #{status}, #{createtime})")
    void addEffect(Effect effect);

    @Update("update tb_effect e  set e.status = '1' where e.id = #{id}")
    void examineEffect(Integer id);
}
